# 152. 乘积最大子数组
# https://leetcode-cn.com/problems/maximum-product-subarray/



class Solution:
    def maxProduct(self, nums):
        max_num = float("-inf")
        imax, imin = 1, 1
        for n in nums:
            if n < 0:
                imax, imin = imin, imax
            imax = max(imax*n, n)
            imin = min(imin*n, n)
            max_num = max(max_num, imax)
        return max_num
